#ifndef SERVERSWINDOW_H
#define SERVERSWINDOW_H

#include "dianewserver.h"
#include "modelserver.h"
#include "mainwindow.h"
#include "filetransferwindow.h"

#include <QMainWindow>
#include <QStandardItemModel>
#include <QStandardItem>
#include <QJsonDocument>
#include <QJsonArray>>
#include <QJsonObject>
#include <QDir>
#include <QMessageBox>

Q_DECLARE_METATYPE(ModelServer);

namespace Ui {
class ServersWindow;
}

class ServersWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit ServersWindow(QWidget *parent = nullptr);
    ~ServersWindow();

private:
    void initUI();
    void saveServers();                         //保存列表到文件
    QList<ModelServer> loadServers();           //加载列表
    void addServerToModel(ModelServer server);  //添加一个实体到模型中

private:
    Ui::ServersWindow *ui;
    QString m_path;                             //程序路径
    QMenu* m_menu;                              //右键菜单
    QStandardItemModel m_servers;
    QMap<QString, MainWindow*> m_mainWins;
    QMap<QString, FileTransferWindow*> m_fileWins;

private slots:
    void on_lvServersPopContextMenu(QPoint p);
    void on_NewServerCallback(bool isNew, ModelServer info);
    void on_actionNewServer_triggered();
    void on_actionEditServer_triggered();
    void on_lvServers_doubleClicked(const QModelIndex &index);
    void on_actionDelServer_triggered();
    void on_actionFileTransfer_triggered();
};

#endif // SERVERSWINDOW_H
